# -*- coding:utf-8 -*-
from Tkinter import *
from ttk import *


class APPControl:
    def __init__(self, action_start, master, label, package_name, activity_name, source_path=""):
        self.action_start = action_start
        self.package_name = package_name
        self.activity_name = activity_name
        self.source_path = source_path

        self.master = Labelframe(master, text=label)
        self.master.pack(side=TOP, expand=True, padx=4, anchor=W)
        Button(self.master, text="卸载应用", command=self.uninstall).pack(side=LEFT, padx=4, pady=2)
        if len(self.source_path) > len("/sdcard/**"):
            Button(self.master, text="清理文件", command=self.clean_file).pack(side=LEFT, padx=4, pady=2)
        Button(self.master, text="清除数据", command=self.clean_data).pack(side=LEFT, padx=4, pady=2)
        Button(self.master, text="强制停止", command=self.force_stop).pack(side=LEFT, padx=4, pady=2)
        Button(self.master, text="打开应用", command=self.open_pp).pack(side=LEFT, padx=4, pady=2)

    def uninstall(self):
        self.action_start("adb_uninstall", package_name=self.package_name)

    def clean_data(self):
        self.action_start("adb_clean_data", package_name=self.package_name)

    def force_stop(self):
        self.action_start("adb_force_stop", package_name=self.package_name)

    def open_pp(self):
        self.action_start("adb_open_apk",
                          package=self.package_name,
                          activity=self.activity_name)

    def clean_file(self):
        self.action_start("adb_remove_file", remote_path=self.source_path, is_rf=True)
